package com.bc.bcapi.service;

import com.bc.bccore.webconfig.WebConfig;
import com.bc.commoncore.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.math.BigInteger;

import com.bc.bcapi.dao.T_File_upload_logMapper;
import com.bc.bcmodel.domain.T_File_upload_logModel;

/**
 * @Name T_File_upload_logService * @Description  * @Author generation * @Date 2018/9/18 14:44:30 * @Version 1.0
 **/
@Service
public class T_File_upload_logService {
    @Resource
    T_File_upload_logMapper t_File_upload_logMapper;

    /**
     * 保存单条数据     *      * @return
     */
    public int insert(T_File_upload_logModel req) {
        return t_File_upload_logMapper.insert(req);
    }

    /**
     * 批量增加数据     *      * @return
     */
    public int insertBatch(List<T_File_upload_logModel> req) {
        return t_File_upload_logMapper.insertBatch(req);
    }

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    public T_File_upload_logModel findByNamedParam(T_File_upload_logModel req) {
        return t_File_upload_logMapper.findByNamedParam(req);
    }

    /**
     * 根据对象查询所有数据     *      * @return
     */
    public List<T_File_upload_logModel> getAllList(T_File_upload_logModel req) {
        return t_File_upload_logMapper.findByNamedParamList(req);
    }

    /**
     * 根据对象查询所有分页数据     *      * @return
     */
    public PageInfo<T_File_upload_logModel> getList(T_File_upload_logModel req) {
        PageHelper.startPage(req.getPage_index(), req.getPage_size());
        List<T_File_upload_logModel> list = t_File_upload_logMapper.findByNamedParamList(req);
        return new PageInfo<T_File_upload_logModel>(list);
    }

    /**
     * 更新指定对象     *      * @return
     */
    public int update(T_File_upload_logModel req) {
        return t_File_upload_logMapper.update(req);
    }

    /**
     * 删除指定数据     *      * @return
     */
    public int delete(BigInteger id) {
        return t_File_upload_logMapper.delete(id);
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    public long count(T_File_upload_logModel req) {
        return t_File_upload_logMapper.count(req);
    }

    /**
     * 过滤图片路径
     */
    public String setFilePath(String path) {
        if (StringUtils.isEmpty(path)) {
            return "";
        }
        return path.replace(WebConfig.getImgUrl(), "");
    }

    /**
     * 获取图片的时候要把图片路径加上去
     */
    public String getFilePath(String path) {
        if (StringUtils.isEmpty(path)) {
            return "";
        }
        String[] arr = path.split("\\|");
        StringBuilder sb = new StringBuilder();
        if (arr != null && arr.length == 1) {
            sb.append(WebConfig.getImgUrl()).append(path);
            return sb.toString();
        }
        for (String item :
                arr) {
            if (StringUtils.isEmpty(item)) {
                continue;
            }
            sb.append(WebConfig.getImgUrl() + item).append("|");
        }
        return sb.toString();
    }
}